package com.leyou.auth.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.auth.entity.ClientInfo;
import com.leyou.auth.mapper.ClientInfoMapper;
import com.leyou.auth.service.ClientService;
import com.leyou.common.exception.LyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class ClientServiceImpl extends ServiceImpl<ClientInfoMapper, ClientInfo> implements ClientService {



    @Autowired
    private PasswordEncoder passwordEncoder;

    @Value("${ly.jwt.key}")
    private String key;

    @Override
    public String getSecretKey(String clientId, String secret) {

        //根据clientId查询对应的client对象信息
        ClientInfo clientInfo = query().eq("client_id", clientId).one();



        if (null==clientInfo|| !passwordEncoder.matches(secret,clientInfo.getSecret())){

            throw new LyException(403,"服务身份校验有误");
        }

        return key;
    }
}
